<template>
  <div class="breadcrumb">
    <el-breadcrumb separator="/" class="breadcrumb-container">
      <el-breadcrumb-item v-for="bread in breadcrumbList" :key="bread.id">{{bread.name}}</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="use-info">
      <el-dropdown>
        <div class="info">
          <el-avatar
            src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"
          ></el-avatar>
          {{name}}
        </div>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item>
              <el-button type="primary" @click="logout">退出登录</el-button>
            </el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue';
import { useRoute, useRouter } from 'vue-router'
import { useLoginStore } from '@/store';
import { routeMapToBreadcrumb } from '@/utils/routeToMenu';
import localCache from '@/utils/cache'
const loginStore = useLoginStore()
const router = useRouter()
const breadcrumbList = computed(() => {
  const currentPath = useRoute().path
  const userMenu = loginStore.roleList
  return routeMapToBreadcrumb(userMenu,currentPath)
})
const name = loginStore.name
const logout = () => {
  localCache.removeCache('token')
  router.push('/login')
}
</script>

<style scoped lang="less">
.breadcrumb{
  display: flex;
  justify-content: space-between;
  .breadcrumb-container{
    line-height: 48px;
  }
}

</style>